<?php

namespace app\api\controller;

use app\common\controller\WxAccessToken;
use EasyWeChat\OfficialAccount\Application;

class WxMenu
{
    use WxAccessToken;

    public object $app;

    public function __construct ()
    {
        $this->app = new Application(config('easy_wechat'));
    }

    /**
     * 创建微信菜单
     * @return void
     */
    public function create ()
    {
        $curl = $this->app->getClient();
        $buttons = [
            [
                "type" => "view",
                "name" => "立即下单",
                "url"  => "https://anmoh5.sdkuma.com"
            ]
        ];
        $ret = $curl->post('https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . self::getAccessToken(), [
            json_encode(['button' => $buttons])
        ]);
        return $ret;
    }
}